//
//  GFOverTimeView.m
//  GoodFood
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 荣伟峰. All rights reserved.
//

#import "GFOverTimeView.h"

@interface GFOverTimeView ()
@property (nonatomic, strong) UILabel *overTimeLabel;
@property (nonatomic, copy) void(^buttonBlock)(UIButton *button);
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation GFOverTimeView
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame withButtonBlock:(void(^)(UIButton *button))block {
    self = [super initWithFrame:frame];
    if (self) {
        [self createImageView];
        [self createLabel];
        [self createButton];
        self.buttonBlock = block;
        self.backgroundColor = [UIColor colorWithRed:0.328 green:0.378 blue:0.412 alpha:0.800];
    }
    return self;
}
#pragma mark - 创建label
- (void)createLabel {
    self.overTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    self.overTimeLabel.center = CGPointMake(ScreenWidth / 2, ScreenHeight / 2 + 60);
    self.overTimeLabel.textAlignment = NSTextAlignmentCenter;
    self.overTimeLabel.text = @"连接失败";
    [self addSubview:self.overTimeLabel];
}
#pragma mark - 创建button
- (void)createButton {
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button.frame = CGRectMake(ScreenWidth / 2 - 50, ScreenHeight / 2 + 80, 100, 20);
    [self.button setTitle:@"刷新" forState:0];
    self.button.backgroundColor = [UIColor orangeColor];
    self.button.layer.masksToBounds = YES;
    self.button.layer.cornerRadius = 5;
    [self.button setTintColor:[UIColor blackColor]];
    [self addSubview:self.button];
    [self.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
}
#pragma mark - button点击
- (void)button:(UIButton *)button {
    self.buttonBlock(button);
}
#pragma mark - 创建imageView
- (void)createImageView {
    NSMutableArray *arr = [NSMutableArray array];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 80)];
    self.imageView.center = CGPointMake(ScreenWidth / 2, ScreenHeight / 2 + 10);
    [self.imageView setBackgroundColor:[UIColor clearColor]];
    for (NSInteger i = 1; i < 5; i++) {
        UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"failed-%ld.png", i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [arr addObject:image];
    }
    [self addSubview:self.imageView];
//    self.imageView.backgroundColor = [UIColor redColor];
    self.imageView.animationImages = arr;
    self.imageView.animationDuration = 0.5;
    self.imageView.animationRepeatCount = CGFLOAT_MAX;
    [self.imageView startAnimating];
    
}
@end
